#include<iostream>
using namespace std;
int gcd(int a, int b) {//辗转相除法求最大公约数，构造函数
    while (b  != 0) {
        int temp = b;
        b = a%b;//两个数的最大公约数等于两个数中较小那个数与两数余数的公约数
        a = temp;
    
    }
    return a;   
}//封装函数

int main(){
    int a, b;
    cin >> a >> b;
    cout << gcd(a, b) << endl;
    return 0;
}
/*以 gcd(56, 98) 为例：

第1轮循环：

a = 56, b = 98

temp = b = 98

b = a % b = 56 % 98 = 56

a = temp = 98

现在：a = 98, b = 56

第2轮循环：

a = 98, b = 56

temp = b = 56

b = a % b = 98 % 56 = 42

a = temp = 56

现在：a = 56, b = 42

第3轮循环：

a = 56, b = 42

temp = b = 42

b = a % b = 56 % 42 = 14

a = temp = 42

现在：a = 42, b = 14

第4轮循环：

a = 42, b = 14

temp = b = 14

b = a % b = 42 % 14 = 0

a = temp = 14

现在：a = 14, b = 0

循环结束，返回 a = 14*/